<template>
	<view class="comeLook">
		
		<!-- 设备出库 --- 查看记录 组件-->
		<baseInput @inputChange="inputChange" @clearInput="clearInput"></baseInput>
		<scroll-view scroll-y="true" class="scroll-box" @scrolltolower="scrolltolower">
			<view class="info">
				<view class="item" v-for="item in deviceList" :key="item.id" @click="getInfoItem(item.code,item.projectName,item.subProjectName)">
					<view class="header">
						<image class="image" src="/subpackage-equipment/static/project1.png" mode="aspectFit"></image>
						<view class="box">
							<view class="t1">{{ item.projectName || "" }}</view>
							<view class="t2">{{ item.subProjectName || "" }}</view>
						</view>
					</view>
					
					<view class="item-body">
						<view class="item-nav">
							<view class="name">出库设备：</view>
							<view class="value">{{ item.eqNames || "" }}</view>
						</view>
						<view class="item-nav">
							<view class="name">出库编号：</view>
							<view class="value">{{ item.code || "" }}</view>
						</view>
						<view class="item-nav">
							<view class="name">提交时间：</view>
							<view class="value">{{ item.time || "" }}</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import baseInput from "@/components/baseInput/baseInput.vue"
	import { getEqExWarehouseList } from "@/api/device/deviceOut.js"
	import mixins from "@/utils/mixins.js"
	export default{
		name: "comeLook",
		mixins: [mixins],
		components: {
			baseInput
		},
		data() {
			return {
				obj: {
					projectOrgId: "",  // 业主组织id
					code: "",          // 设备入库编号
					requestMode: "app"
				},
				pagination:{
					total: "",
					pageSize: 10,
					currentPage: 1
				},
				deviceList: [],       // 设备出库列表
				bool: false,
			}
		},
		mounted() {
			this.getList()
		},
		methods: {
			scrolltolower(){
				this.pagination.currentPage ++
				this.getList()
			},
			
			getList(){
				// 在发送请求就不在发送请求
				if(this.bool){
					return
				}
				if(this.pagination.total !== "" &&  this.deviceList.length !==0  && this.deviceList.length >= this.pagination.total ){
					uni.showToast({
						icon: "none",
						title: "到底了"
					})
					return
				}
				this.bool = true
				let _query={
					currPage: this.pagination.currentPage,
					pageSize: this.pagination.pageSize,
					params: this.obj
				}
				getEqExWarehouseList(_query).then(res=>{
					let list = res.result.list.map(item=>({...item,time:this.getDate2(item.recordCreateDate)}))
					list.forEach(item=>{
						if(item.projectCascade){
							item.projectName = item.projectCascade.split("/")[0] || ""
							item.subProjectName = item.projectCascade.split("/").length > 1 ? (item.projectCascade.split("/")[1] || '' +'/'+item.projectCascade.split("/")[2] || "") : ''
						}
					})
					this.deviceList = [...this.deviceList, ... list]
					this.pagination.total = res.result.total
					this.bool = false
					console.log(this.deviceList)
				})
			},
			
			inputChange(value){
				console.log(value,'value')
				if(value){
					this.obj.code=value
				}else {
					this.obj.code=""
				}
				// clearTimeout(this.time)
				// this.time = setTimeout(()=>{
					this.pagination.currentPage = 1
					this.deviceList = []
					this.obj.code = value
					this.getList()
				// },500)
			},
			
			clearInput(){
				this.pagination.currentPage = 1
				this.deviceList = []
				this.obj.code = ""
				this.getList()
			},
			
			getInfoItem(code,projectName,subProjectName){
				console.log(code,'code')
				uni.navigateTo({
					url: `/subpackage-equipment/pages/device/deviceCome/components/comeInfo?code=${code}&projectName=${projectName}&subProjectName=${subProjectName}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.comeLook{
		padding-top: 20rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		.scroll-box{
			height: calc(100vh - 460rpx);
			padding-top: 10rpx;
			
		}
		.info{
			padding-top: 34rpx;
			.item{
				width: 100%;
				// height: 384rpx;
				height: auto;
				background: linear-gradient(180deg, #FFFFFF 0%, rgba(255, 255, 255, 0) 100%);
				box-shadow: 0rpx 0rpx 34rpx 2rpx rgba(47, 128, 237, 0.1);
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				padding: 20rpx 35rpx;
				box-sizing: border-box;
				margin-bottom: 36rpx;
				
				.header{
					height: auto;
					display: flex;
					align-items: center;
					border-bottom: 2rpx solid #E0E7F6;
					.image{
						width: 70rpx;
						height: 70rpx;
						margin-right: 44rpx;
						margin-left: 12rpx;
					}
					.box{
						flex: 1;
						.t1{
							font-size: 32rpx;
							font-weight: bold;
							color: #445469;
							margin-bottom: 10rpx;
						}
						.t2{
							font-size: 28rpx;
							font-weight: 500;
							color: #6A819E;
						}
					}
				}
				.item-body{
					font-size: 28rpx;
					font-weight: 500;
					color: #445469;
					padding-left: 10rpx;
					padding-top: 20rpx;
					.item-nav{
						display: flex;
						margin-top: 22rpx;
						.name{
							width: 140rpx;
						}
						.value{
							width: 360rpx;
							white-space:nowrap;
							overflow:hidden;
							text-overflow:ellipsis;
						}
					}
				}
			}
		}
	}
</style>
